package bz.ziro.kanbe.controller.mng.agent;

import java.util.Date;
import java.util.logging.Logger;
import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.datastore.Datastore;
import org.slim3.util.BeanUtil;

import bz.ziro.kanbe.dao.UserAgentDao;
import bz.ziro.kanbe.model.UserAgent;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

/**
 * エージェントの更新を行う
 * @author Administrator
 */
public class UpdateController extends Controller {

    @SuppressWarnings("unused")
    private static final Logger logger = Logger.getLogger(UpdateController.class.getName());

    @Override
    public Navigation run() {

        String keyBuf = param("agentKey");
        //検索する
        UserAgent agent = UserAgentDao.find(Long.valueOf(keyBuf));
        BeanUtil.copy(request, agent);

        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();
        //作成日を設定
        agent.setEditDate(new Date());
        agent.setEditor(user);

        Datastore.put(agent);
        return null;
    }
}
